﻿
using DrCarDrive.Util;
using DrCarDrive.Wpf;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using MahApps.Metro.Controls;
using DrCarDrive.Wpf.WpfPage;

namespace DrCarDrive.Wpf.WpfWindow
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : MetroWindow
    {
        private static MainWindow instance;       

        private MainWindow()
        {
            InitializeComponent();
            ContentFrame.Content = LoginPage.Instance;
            instance = this;
        }

        public static MainWindow Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new MainWindow();
                }

                return instance; 
            }
        }

        private void ShutDownButton_Click(object sender, RoutedEventArgs e)
        {

        }

        private void DoctorHomePageButton_Click(object sender, RoutedEventArgs e)
        {
            MainWindow.Instance.ContentFrame.Content = DashboardPage.Instance;
        }

        private void LogoutPageButton_Click(object sender, RoutedEventArgs e)
        {
            //MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Do you want to Logout from the system?", "Logout", System.Windows.MessageBoxButton.YesNo);
            ConfirmationWindow cfw = new ConfirmationWindow("Logout","Are sure you want to signout?");
            cfw.ShowDialog();
            MessageBoxResult messageBoxResult = ConfirmationWindow.isConfirm;
            if (messageBoxResult == MessageBoxResult.Yes)
            {
                SessionData.clearAll();
                MainWindow.Instance.TopMenu.Visibility = System.Windows.Visibility.Hidden;
                MainWindow.Instance.lblCarNo.Content = "";
                MainWindow.instance.ContentFrame.Content = LoginPage.Instance;
            }
        }

        private void Button_MouseDoubleClick_1(object sender, MouseButtonEventArgs e)
        {
            MainWindow.instance.ContentFrame.Content = DrCarDrive.Wpf.WpfPage.Settings.Instance;
        }

        private void btnHome_Click(object sender, RoutedEventArgs e)
        {
            MainWindow.instance.ContentFrame.Content = DashboardPage.Instance;
        }

        private void MetroWindow_SizeChanged_1(object sender, SizeChangedEventArgs e)
        {
            var screenWidth = System.Windows.SystemParameters.PrimaryScreenWidth;
            MainWindow.Instance.Left = (screenWidth - MainWindow.Instance.Width) / 2;
        }

        internal void setFlyOutValues(tbl_places place, List<IssueMedicineView> medicine)
        {
            lblArrivalDateTime.Content = place.ARRIVAL_DATE.ToString();
            lblDepatureDateTime.Content = place.DEPARTURE_DATE.ToString();
            lblVisitDuration.Content = FindDifference.calculateDuration(place.ARRIVAL_DATE,place.DEPARTURE_DATE);
            lblPatients.Content = place.NUMBER_PATIENT.ToString();
            lblDoctors.Content = place.NUMBER_DOCTORS.ToString();
            lblParamedics.Content = place.NUMBER_PARAMEDICS.ToString();
            txtPlaceRemark.Text = place.REMARK;

            gridIssuedMedicine.ItemsSource = medicine;
            Instance.flyHistoryDetails.IsOpen = true;
        }

        private void btnChangePassword_Click(object sender, RoutedEventArgs e)
        {
            PasswordChangeWindow.Instance.ShowDialog();
        }
    }
}
